/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bpmlab.shift.dao;

import bpmlab.shift.dao.service.GenericDAO;
import bpmlab.shift.dao.service.TransporteDAO;
import bpmlab.shift.entity.Processo;
import bpmlab.shift.entity.Transporte;
import java.util.List;
import javax.persistence.EntityManager;

/**
 *
 * @author Mikael Lima
 */
public class TransporteDAOJpa implements TransporteDAO {

    private final GenericDAO<Transporte> dao = DAOFactory.criarGenericDAO(Transporte.class);

    @Override
    public void salvar(Transporte o) throws DAOException {
        dao.salvar(o);
    }

    @Override
    public void excluir(Transporte o) throws DAOException {
        dao.excluir(o);
    }

    @Override
    public Transporte obter(Object id) {
        return dao.obter(id);
    }

    @Override
    public List<Transporte> obterTodos() {
        return dao.obterTodos();
    }
    
    @Override
    public List<Transporte> obterPorProcesso(Processo processo) throws DAOException {
        EntityManager manager = JpaUtil.getEntityManager();
        String jpql = "select t from Transporte t where t.processo = :processo";
        return manager.createQuery(jpql, Transporte.class)
                .setParameter("processo", processo)
                .getResultList();
    }

}
